/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Admin.DAO;

import Admin.Model.PostHistory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.nio.cs.HistoricallyNamedCharset;

/**
 *
 * @author home
 */
public class PostHistoryDAO {

    private Connection myCon;
    private PreparedStatement ps;
    private ResultSet rs;
    private String strCommand = "";
    public ArrayList<PostHistory> GetAll ()
    {
         ArrayList<PostHistory> listHistory= new ArrayList<PostHistory>();
         PostHistory post =  null;
        try {

            strCommand = "SELECT * FROM tbl_PostHistory";
            myCon=myConnection.getConnection();
            myConnection.getConnection();
            ps = myCon.prepareStatement(strCommand);
           
            rs=ps.executeQuery();
            while(rs.next())
            {
                post=new PostHistory();
                
                post.setPostHistoryID(rs.getInt("postHistoryID"));
                post.setUserID(rs.getInt("userID"));
                post.setPostTypeID(rs.getInt("postTypeID"));
                post.setRealEstateID(rs.getInt("RealEstateID"));
                post.setStartDate(rs.getString("startDate"));
                post.setPrice(rs.getString("price"));
                post.setEndDate(rs.getString("endDate"));
                post.setPostHistoryStatus(rs.getInt("postHistoryStatus"));

                listHistory.add(post);
            }
            return listHistory;
        } catch (SQLException ex) {
            Logger.getLogger(PostHistoryDAO.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
              myConnection.closeConnection(myCon, ps, rs);
        }
        return listHistory;
    }
    public  PostHistory GetByID (int postHistoryID)
    {
            PostHistory post =  new PostHistory();
        try {

            strCommand = "SELECT * FROM tbl_PostHistory WHERE postHistoryID = ?";
            myCon=myConnection.getConnection();
            myConnection.getConnection();
            ps = myCon.prepareStatement(strCommand);
            ps.setInt(1, postHistoryID);
            rs=ps.executeQuery();
            while(rs.next())
            {

                post.setPostHistoryID(rs.getInt("postHistoryID"));
                post.setUserID(rs.getInt("userID"));
                post.setPostTypeID(rs.getInt("postTypeID"));
                post.setRealEstateID(rs.getInt("RealEstateID"));
                post.setStartDate(rs.getString("startDate"));
                post.setPrice(rs.getString("price"));
                post.setEndDate(rs.getString("endDate"));
                post.setPostHistoryStatus(rs.getInt("postHistoryStatus"));
            }
            return post;
        } catch (SQLException ex) {
            Logger.getLogger(PostHistoryDAO.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
              myConnection.closeConnection(myCon, ps, rs);
        }
        return post;
    }
}
